package com.dj.mingkong.common.microservice;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SpringCloudMicroServiceContext extends AbstractMicroServiceContext {
    private Map<String, String> mapContext = new ConcurrentHashMap();

    public SpringCloudMicroServiceContext() {
    }

    private String convertKey(String key) {
        return createContextKey(key.toLowerCase());
    }

    public void setAttachment(String key, String attachment) {
        if (attachment != null) {
            this.mapContext.put(this.convertKey(key), attachment);
        } else {
            this.removeAttachment(key);
        }

    }

    public void removeAttachment(String key) {
        this.mapContext.remove(this.convertKey(key));
    }

    public String getAttachment(String key) {
        return (String) this.mapContext.get(this.convertKey(key));
    }

    public void removeContext() {
        this.mapContext.clear();
    }

    public Map<String, String> getAttachments() {
        return this.mapContext;
    }
}
